using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;

public partial class Admin_ChangePass : System.Web.UI.Page
{
    protected long Id
    {
        get
        {
            object o = ViewState["Id"];
            if (o != null)
                return (long)o;
            return long.MinValue;
        }
        set
        {
            ViewState["Id"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        LoadData();



    }
    #region LoadData
    private void LoadData()
    {
        if (Session["userid"] != null)
        {
            ADESSA.Entities.User _user = UserService.GetUser(long.Parse(Session["userid"].ToString()));
            if (_user != null)
            {
                txtName.Value = _user.UserName;
                this.Id = _user.UserId;
            }
        }
    }

    #endregion
    protected void saveButton_Click(object sender, EventArgs e)
    {
        ADESSA.Entities.User user = new ADESSA.Entities.User();
        user = UserService.GetUser(this.Id);
        if (user != null)
        {
            try
            {
                if (user.Password == Utilitys.Encrypt(txtPassword.Value))
                {
                    user.Password = Utilitys.Encrypt(txtRetypePassword.Value);
                    UserService.UpdateUser(user);
                    lblmsg.Text = "Change password success";
                }
                else
                {
                    lblmsg.Text = "Old password is incorrect";
                }

            }
            catch (Exception)
            {

                lblmsg.Text = "Change Password Unsuccess.";
            }

        }
    }
    protected void cancelButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}

